/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.shop.web.activity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.shop.entity.activity.HkShopDiscount;
import com.thinkgem.jeesite.modules.hk.shop.service.activity.HkShopDiscountService;

/**
 * 乐购折扣专场Controller
 * @author 罗天文
 * @version 2018-05-16
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/activity/hkShopDiscount")
public class HkShopDiscountController extends BaseController {

	@Autowired
	private HkShopDiscountService hkShopDiscountService;
	
	@ModelAttribute
	public HkShopDiscount get(@RequestParam(required=false) String id) {
		HkShopDiscount entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkShopDiscountService.get(id);
		}
		if (entity == null){
			entity = new HkShopDiscount();
		}
		return entity;
	}
	
	@RequiresPermissions("shop:activity:hkShopDiscount:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkShopDiscount hkShopDiscount, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkShopDiscount> page = hkShopDiscountService.findPage(new Page<HkShopDiscount>(request, response), hkShopDiscount); 
		model.addAttribute("page", page);
		return "hk/shop/activity/hkShopDiscountList";
	}

	@RequiresPermissions("shop:activity:hkShopDiscount:view")
	@RequestMapping(value = "form")
	public String form(HkShopDiscount hkShopDiscount, Model model) {
		model.addAttribute("hkShopDiscount", hkShopDiscount);
		return "hk/shop/activity/hkShopDiscountForm";
	}

	@RequiresPermissions("shop:activity:hkShopDiscount:edit")
	@RequestMapping(value = "save")
	public String save(HkShopDiscount hkShopDiscount, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkShopDiscount)){
			return form(hkShopDiscount, model);
		}
		hkShopDiscountService.save(hkShopDiscount);
		addMessage(redirectAttributes, "保存乐购折扣专场成功");
		return "redirect:"+Global.getAdminPath()+"/shop/activity/hkShopDiscount/?repage";
	}
	
	@RequiresPermissions("shop:activity:hkShopDiscount:edit")
	@RequestMapping(value = "delete")
	public String delete(HkShopDiscount hkShopDiscount, RedirectAttributes redirectAttributes) {
		hkShopDiscountService.delete(hkShopDiscount);
		addMessage(redirectAttributes, "删除乐购折扣专场成功");
		return "redirect:"+Global.getAdminPath()+"/shop/activity/hkShopDiscount/?repage";
	}

}